using System;
using System.IO;
using CodePlex.TfsLibrary.ObjectModel;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("add", "Schedule files and/or directories for addition during the next commit.", MinArgs = 1, UsageSummary = "<path...> [options]")]
    public class AddCommand : NonAuthenticatedCommand
    {
        bool recursive;

        [Option("recursive", "act recursively on directories", ShortName = "e")]
        public bool Recursive
        {
            get { return recursive; }
            set { recursive = value; }
        }

        public override void Execute()
        {
            foreach (string path in Arguments)
                Engine.Add(CodePlexClientUtil.GetFullPath(path), recursive, OnSourceItem);
        }

        static void OnSourceItem(SourceItem item,
                                 SourceItemResult result)
        {
            if (result != SourceItemResult.S_Ok)
                ConsoleUtil.PrintCommandError(item.LocalName, result);
            else
                Console.WriteLine("A    {0}", CodePlexClientUtil.GetRelativePath(Directory.GetCurrentDirectory(), item.LocalName));
        }
    }
}